#ifndef XMPPMUC_H
#define XMPPMUC_H

#include <QObject>
#include <QDebug>

#include "QXmppMucManager.h"
#include "QXmppMessage.h"

class XmppMuc : public QObject
{
    Q_OBJECT

    Q_PROPERTY( QXmppMucManager* mucManager READ getMucManager WRITE setMucManager NOTIFY mucManagerChanged )
    Q_PROPERTY( QString jidRoom READ getJidRoom WRITE setJidRoom NOTIFY jidRoomChanged )
    Q_PROPERTY( QString nickName READ getNickName WRITE setNickName NOTIFY nickNameChanged )
    Q_PROPERTY( QString password READ getPassword WRITE setPassword NOTIFY passwordChanged )
    Q_PROPERTY( QString subjectRoom READ getSubjectRoom WRITE subjectRoomChangedAction NOTIFY subjectRoomChanged )

    QXmppMucManager* m_mucManager;
    QXmppMucRoom* m_mucRoom;

    QString m_jidRoom;
    QString m_myNickName;
    QString m_myPasswd;
    QString m_subjectRoom;

public:
    explicit XmppMuc(QObject *parent = 0);

    Q_INVOKABLE QStringList getParticipants();
    Q_INVOKABLE bool sendMessage( const QString text );
    Q_INVOKABLE QString getNameByJid( const QString mucJid ) const;
    Q_INVOKABLE void leaveChat();

    //Q_INVOKABLE void joinRoom(  const QString &nickName,  const QString &passwd );


    /*---- getter / setter ----*/
    QString getSubjectRoom() const { return m_subjectRoom; }

    QXmppMucManager* getMucManager() const { return m_mucManager; }
    QString getJidRoom() const { return m_jidRoom; }

    QString getNickName() const { return m_myNickName; }
    void setNickName( const QString &_myName ) { m_myNickName = _myName; }

    QString getPassword() const { return m_myPasswd; }
    void setPassword( const QString &_myPass ) { m_myPasswd = _myPass; }

signals:

    void mucManagerChanged();
    void invitationMucReceived(const QString &roomJid, const QString &inviterJid, const QString &reason);
    void jidRoomChanged(QString arg);
    void messageReceived();
    void nickNameChanged();
    void passwordChanged();
    void participantChanged(QString nickName);
    void participantAdded(QString nickName);
    void participantRemoved(QString nickName);
    void messageReceived( QString nickName, QString textMessage );
    void subjectRoomChanged (const QString &subject);

private slots:
    void participantChangedAction(QString jid);
    void participantAddedAction(QString jid);
    void participantRemovedAction(QString jid);
    void messageReceivedAction(const QXmppMessage &message);
    void subjectRoomChangedAction( const QString &subject );


public slots:

    void setMucManager(QXmppMucManager* arg);
    void setJidRoom(QString jid);

private:
    QString resourceAsNickName( const QString &jid ) const;
};

#endif // XMPPMUC_H
